package com.oa.system.controller;

import com.joneying.common.web.response.Resp;
import com.oa.core.exception.BusinessException;
import com.oa.core.exception.DataIsEmptyException;
import com.oa.system.dto.PostAddDTO;
import com.oa.system.dto.PostListDTO;
import com.oa.system.dto.PostUpdateDTO;
import com.oa.system.entity.Post;
import com.oa.system.service.IPostService;
import com.oa.system.vo.PostDetailsVO;
import com.oa.system.vo.PostListVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.joneying.common.annotation.CommonController;
import org.springframework.context.annotation.Description;

import java.util.Date;
import java.util.List;

import org.springframework.web.bind.annotation.RestController;
import com.oa.core.BaseController;
import springfox.documentation.annotations.ApiIgnore;

import javax.servlet.http.HttpServletRequest;

/**
 * @author syb123
 * @since 2019-01-29
 */
@RestController
@RequestMapping("/post")
@Api(description = "岗位表模块")
//@ApiIgnore
public class PostController extends BaseController {

    private final IPostService postService;

    @Autowired
    public PostController(IPostService postService) {
        this.postService = postService;
    }


    @GetMapping("/list")
    @CommonController
    @Description("查询岗位列表")
    @ApiOperation(value = "查询")
    public Resp<PostListVO> list(PostListDTO postListDTO){
        return new Resp().success(postService.findPostList(postListDTO));
    }

    @GetMapping("/{id}")
    @CommonController
    @Description("根据ID查询")
    @ApiOperation(value = "查询")
    public Resp<PostDetailsVO> objById(@ApiParam("ID") @PathVariable String id) throws DataIsEmptyException {
        return postService.findPostDetailsById(id);
    }

    /**
     * 新增
     *
     * @param postAddDTO PostAddDTO
     * @return Resp
     */
    @PostMapping("")
    @CommonController
    @Description("新增")
    @ApiOperation(value = "新增")
    public Resp add(@ApiParam(value = "岗位表对象") PostAddDTO postAddDTO) throws BusinessException {
        return postService.addPost(postAddDTO);
    }

    /**
     * 根据Id修改
     *
     * @param post Post
     * @return Resp
     */
    @PutMapping("")
    @CommonController
    @Description("根据id修改")
    @ApiOperation(value = "根据id修改")
    public Resp update(@ApiParam(value = "岗位表对象") @RequestBody(required = false) PostUpdateDTO post) throws BusinessException {
        return postService.updatePostDetailsById(post);
    }

    /**
     * 根据Id删除
     *
     * @param id id
     * @return Resp
     */
    @DeleteMapping("/{id}")
    @CommonController
    @Description("根据id删除")
    @ApiOperation(value = "根据id删除")
    public Resp delete(@ApiParam(value = "id", required = true) @PathVariable("id") String id) throws BusinessException, DataIsEmptyException {
        return postService.deletePostDetailsById(id);
    }
}
